﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Library.DAL
{
    public class ChiTietHoaDonXuatDAL
    {
        public static void Add(BIZ.ChiTietHoaDonXuatBIZ chitiet)
        {
            NETMobileEntities db = new NETMobileEntities();
            DAL.ChiTietHoaDonXuat c = new ChiTietHoaDonXuat();
            c.ID_HoaDonXuat = chitiet.ID_HoaDonXuat;
            c.ID_SanPham = chitiet.ID_SanPham;
            c.DonGia = chitiet.DonGia;
            c.SoLuong = chitiet.SoLuong;
            db.ChiTietHoaDonXuats.AddObject(c);
            db.SaveChanges();
        }

        public static void Delete(BIZ.ChiTietHoaDonXuatBIZ chitiet)
        {
            NETMobileEntities db = new NETMobileEntities();
            var r = (from a in db.ChiTietHoaDonXuats 
                    where a.ID == chitiet.ID
                    select a).First();

            db.ChiTietHoaDonXuats.DeleteObject(r);
            db.SaveChanges();

        }

        public static List<BIZ.ChiTietHoaDonXuatBIZ> FindByHoaDon(BIZ.HoaDonXuatBIZ h)
        {
            List<BIZ.ChiTietHoaDonXuatBIZ> listchitiet = new List<BIZ.ChiTietHoaDonXuatBIZ>();

            NETMobileEntities db = new NETMobileEntities();
            var r = from a in db.ChiTietHoaDonXuats
                    where a.ID_HoaDonXuat == h.ID
                    select a;

            foreach (DAL.ChiTietHoaDonXuat c in r)
            {
                BIZ.ChiTietHoaDonXuatBIZ chitiet = new BIZ.ChiTietHoaDonXuatBIZ();
                chitiet.ID = c.ID;
                chitiet.ID_HoaDonXuat = c.ID_HoaDonXuat;
                chitiet.ID_SanPham = c.ID_SanPham;
                chitiet.DonGia = c.DonGia;
                chitiet.SoLuong = c.SoLuong;
                listchitiet.Add(chitiet);
            }
            return listchitiet;
        }
    }
}
